/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts.fillSelects;

import com.myapp.model.estados.Estados;
import com.myapp.model.usuaLeng.Usualeng;
import com.myapp.model.usuarios.Usuarios;
import com.myapp.svc.selects.SelectsSvc;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.sql.Select;

/**
 *
 * @author jaime
 */
public class FillSelectsAction extends org.apache.struts.action.Action {

    /*
     * forward name="success" path=""
     */
    private static final String SUCCESS = "success";
    int niv = 0;
    
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        Usuarios usr = new Usuarios();
        
        Usualeng usuaLeng = new Usualeng();
        
        HttpSession session = request.getSession();
        
        usr = (Usuarios) session.getAttribute("usuario");
        
        for (Iterator it = usr.getUsualengs().iterator(); it.hasNext();) {
            usuaLeng = (Usualeng) it.next();
            niv = usuaLeng.getNivel().getIdnivel();
        }
        SelectsSvc selSvc = new SelectsSvc();

        List listEstadoUsuario = selSvc.usuariosEstados();
        session.setAttribute("listaestadosusuarios", listEstadoUsuario);
        
        List listEstado = selSvc.todosLosEstados();
        session.setAttribute("estados", listEstado);

        List listTopics = selSvc.todosLosTemas();
        session.setAttribute("temas", listTopics);

        List listTopicsByLevel = selSvc.temasPorNivel(niv);
        session.setAttribute("temasPorNivel", listTopicsByLevel);
        return mapping.findForward(SUCCESS);
    }
}
